package com.junchenrobot.mes.handler;


import com.junchenrobot.mes.response.BaseResponse;
import com.junchenrobot.mes.response.impl.MesResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理程序
 *
 * @author SeaWave
 * @date 2022/10/19
 */
@Slf4j
@Component
@RestControllerAdvice("com.junchenrobot.mes.controller")
public class GlobalExceptionHandler {
    
    @ExceptionHandler(Exception.class)
    public BaseResponse methodArgumentNotValidException(Exception e) {
        e.printStackTrace();
        log.error(e.getMessage(), e);
        return new MesResponse<>().fault(e.getMessage());
    }
    
    
}
